package com.ccbooks.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class DBHelper extends SQLiteOpenHelper {

	private static DBHelper helper;

	public static final String DATABASE_NAME = "books.db";
	public static final int DATEBASE_VERSION = 1;
	public static final String CREATE_TABLE = "CREATE TABLE ccb_book ( _id integer primary key AUTOINCREMENT , bookname text NOT NULL, author text DEFAULT NULL, publisher text DEFAULT NULL,  seller text DEFAULT NULL, category 	text DEFAULT NULL, booktype text DEFAULT NULL, language text DEFAULT NULL, imgpath text DEFAULT NULL,  		bookpath text DEFAULT NULL,  description text DEFAULT 	NULL,  bookmark text,finalpage text,fileLength int,fileex text,curIndex int) ";
	public static final String CREATE_TABLE1= "CREATE TABLE ccb_marks(_id integer primary key AUTOINCREMENT ,title text DEFAULT NULL,page integer,date integer,bookid integer)";

	// books�и��ֶ���
	public static final String TABLE_BOOK = "ccb_book";
	public static final String TABLE_MARKS="ccb_marks";
	
	public static final String ID = "_id";
	public static final String BOOKNAME = "bookname";
	public static final String AUTHOR = "author";
	public static final String PUBLISHER = "publisher";
	public static final String SELLER = "seller";
	public static final String CATEGORY = "category";
	public static final String BOOKTYPE = "booktype";
	public static final String LANGUAGE = "language";
	public static final String IMGPATH = "imgpath";
	public static final String BOOKPATH = "bookpath";
	public static final String DESCRIPT = "descript";
	public static final String BOOKMARK = "bookmark";
	public static final String FINALPAGE = "finalpage";
	public static final String FILE_LENGTH = "fileLength";
	public static final String FILE_EX = "fileex";
	public static final String CURINDEX = "curIndex";

	private DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATEBASE_VERSION);
		// TODO Auto-generated constructor stub
	}

	public static DBHelper getHelper(Context context) {
		if (helper == null) {
			helper = new DBHelper(context);
		}
		return helper;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_TABLE);
		db.execSQL(CREATE_TABLE1);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("drop table if exists "+TABLE_BOOK);
		db.execSQL("drop table if exists "+TABLE_MARKS);
		onCreate(db);
	}

}
